<?php

//处理 Bootstrap各种自定义
class BootExtend {
    //返回时间
    public static function OrderTime($time)
    {
       return date('Y-m-d H:i:s',$time);
    }
    //返回付款状态
    public static function OrderStatus($status)
    {
       if($status==1)
           return "<span style='color:#1DB7DD'>已付款</span>";
       elseif($status==2)
           return "<span style='color:red'>未付款</span>";
       elseif($status==3)
           return "<span style='color:#ff5858'>已结款</span>";
    }
    //返回车牌号
    public static function OrderCar($id)
    {
        //return $id;
        $sql = "select a1.car_area_id,a1.car_number,a2.* from xc_user_car a1  "
                . " left join xc_area a2 on a2.id=a1.car_area_id where a1.id= ".$id;
         $car_name = Yii::app()->db->createCommand($sql)->queryAll();
         $car_number='';
         if($car_name)
         {
             $car_number =$car_name[0]['shortname'].$car_name[0]['car_number'];
         }
         
         return $car_number;
    }
    //返回input框
    public static function OrderInput($id,$name)
    {
        return "<input type='text' name='{$name}'  id='{$id}' maxlength=50>";
    }
    //返回权限状态
    public static function OrderRoleStatus($status)
    {
        if($status==1)
           return '正常';
       elseif($status==2)
           return '禁用';
    }
    //任意时间撮今天 today();
    public static function ToDay($t='')
    {
        $t = $t?$t:time();
        $today=array();
        $today['start'] = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
        $today['end'] = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
        return $today;
    }
    //任意时间撮昨天YesTerDay()
    public static function YesTerDay($t='')
    {
        $t = $t?$t:time();
        $yesterday=array();
        $yesterday['start'] = mktime(0,0,0,date("m",$t),date("d",$t)-1,date("Y",$t));
        $yesterday['end'] = mktime(23,59,59,date("m",$t),date("d",$t)-1,date("Y",$t));
        return $yesterday;
    }
    //任意周的开始和结束$end_week  = date('W',time());
    //start  $week_start= $this->getTimeOfWeek(2014,$end_week,0);
    //end    $week_end  = $this->getTimeOfWeek(2014,$end_week,1);
    public static function  getTimeOfWeek($year=2014,$week=15,$dir=0)
    {
        return strtotime(sprintf("+%d weeks",$week-($dir?0:1)),mktime(0,0,0,1,-1,$year))-($dir?1:0);
    }
    //任意月份开始和结束 mFristAndLast($y,$m)
    public static function mFristAndLast($y=0,$m=0)
    {
            $y = $y ? $y : date('Y');
            $m = $m ? $m : date('m');
            $d = date('t', strtotime($y.'-'.$m));
            return array("start"=>strtotime($y.'-'.$m),"end"=>mktime(23,59,59,$m,$d,$y));
    }
    //任意年的开始结束时间撮 YearTime()
    public static function YearTime($y='')
    {
        $y = $y?$y:date('Y',time());
        $year_start = $y . "-01-01 00:00:00";   
        $year_end = $y . "-12-31 23:59:59";  
        return array('start'=>strtotime($year_start),'end'=>strtotime($year_end));
    }
    
    
     public static function LastWeek($t='')
    {
        $t = $t?$t:time();
        $lastweek=array();
        $lastweek['start'] = mktime(0,0,0,date("m",$t),date("d",$t)-7,date("Y",$t));
        $lastweek['end'] = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
        return $lastweek;
    }
    
     public static function  PastDays($day)
    {
        $t =time();
        $PastDays=array();
        $lastweek['start'] = mktime(0,0,0,date("m",$t),date("d",$t)-$day,date("Y",$t));
        $lastweek['end'] = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
        return $lastweek;
    }
    
     public static function  PastMonth($month)
    {
        $y=date('Y');
        $m= date('m');
        $d= date('d');
        $pm=$m-$month;
        //$t =time();      
        if($pm>0){//判断捡6个月后 有没有超过今年
            
            $PastMonth['start'] = mktime(0,0,0,$pm,'01',$y);
            $PastMonth['end'] = mktime(23,59,59,$m,$d,$y);
            
        } 
        else{
            $PastMonth['start'] = mktime(0,0,0,12-$pm,'01',$y-1);
            $PastMonth['end'] = mktime(23,59,59,$m,$d,$y);
        }
        return $PastMonth;
    }
    
    
     public static function  ArbitrarilyPastDays($day)//过去某一天的时间
    {
        $t =time();
        $PastDays=array();
        $lastData['start'] = mktime(0,0,0,date("m",$t),date("d",$t)-$day,date("Y",$t));
        $lastData['end'] = mktime(23,59,59,date("m",$t),date("d",$t)-$day,date("Y",$t));
        
        
        return $lastData;
    }
    
     public static function  ArbitrarilyPastMonth($month)//过去某月
    {
        $y=date('Y');
        $m= date('m');
        $d= date('d');
        $pm=$m-$month;

        if($pm>0){//判断6个月后 有没有超过今年
            $ptime=  strtotime("$y-$pm-$d");
            $PastMonth['start'] = mktime(0,0,0,$pm,'01',$y);
            $PastMonth['end'] = mktime(23,59,59,$pm,date('t',$ptime),$y);
            
            
        } 
        else{
            $PastMonth['start'] = mktime(0,0,0,12-$pm,'01',$y-1);
            $PastMonth['end'] = mktime(23,59,59,12-$pm,date('t',12-$pm),$y);
        }
        
        // p($ptime);
        return $PastMonth;
    }
    
    
    public static function Script_price()
    {
       echo "<script language='javascript'>"; 
       echo "var bb=0;";
       echo "for(var i=0;i<$(\"tbody tr td:last-child\").length;i++)";
       echo "{";
       echo "      bb +=  parseFloat($($(\"tbody tr td:last-child\")[i]).html());";
       echo "}";
       $bac =  "documert.write(bb);";
       echo "</script>";
       return $bac;
       //return 
    }
    //返回倒计时时间
    public static function Stime_dao($now)
    {
        $time = time();//当前时间
        $wu_wu = 60*5;
        $fen_wu  = $time-$wu_wu;//5分钟
        $fen_ten = $time-$wu_wu*2;//10分钟
        $fen_sve = $time-$wu_wu*6;//30分钟
        $fen_one = $time-$wu_wu*12;//1 house
        $fen_two = $time-$wu_wu*24;//2 house
        $fen_svv = $time-$wu_wu*36;//3 house
        $fen_fiv = $time-$wu_wu*48;//4 house
       if($now >= $fen_wu)
            return "5分钟前";
       elseif($now >= $fen_ten)
           return "10分钟前";
       elseif($now >= $fen_sve)
           return "30分钟前";
       elseif($now >= $fen_one)
           return "1小时前";
       elseif($now >= $fen_two)
           return "2小时前";
       elseif($now >= $fen_svv)
           return "3小时前";
       elseif($now >= $fen_fiv)
           return "4小时前";
       else
           return date('H:i:s',$now);
    }
    //洗车类型
    public static function Car_type($car_id)
    {
    	$type_ids_temp='';
    	 switch ($car_id) {
            case 1: case 2: 
            	$type_ids_temp = '标准洗车';
                	break;
            case 3: case 4: 
                	$type_ids_temp = '精致洗车';
                  break;
           case 5: case 6:
                	$type_ids_temp = '车身打蜡';
        	      break;
           case 7: case 8:
                	$type_ids_temp = '镀膜';
			break;
	      case 9:
                	$type_ids_temp = '维修';
			break;
		default:
					$type_ids_temp = '标准洗车';
           break;
            }
		return $type_ids_temp;
    }
    //洗车类型_细
    public static function Car_type_xi($car_id)
    {
    	$type_ids_temp='';
    	 switch ($car_id) {
            case 1: 
            	$type_ids_temp = '标准洗车(5座)';
                break;
             case 2: 
            	$type_ids_temp = '标准洗车(7座)';
                break;
            case 3: 
                $type_ids_temp = '精致洗车(5座)';
                 break;
            case 4: 
                $type_ids_temp = '精致洗车(7座)';
                break;
           case 5:
                $type_ids_temp = '车身打蜡(5座)';
        	 break;
           case 6:
                $type_ids_temp = '车身打蜡(7座)';
        	 break;
           case 7: 
                $type_ids_temp = '镀膜(5座)';
		break;
          case 8:
                $type_ids_temp = '镀膜(5座)';
		break;
	  case 9:
                $type_ids_temp = '维修';
		break;
	 default:
              $type_ids_temp = '标准洗车';
              break;
            }
	return $type_ids_temp;
    }
    //返回结款类型
    public static function Checkout_type($type)
    {
        $info = '';
        switch ($type)
        {
            case 1:
                $info = "月结";
                break;
            case 2:
                $info = "充值";
                break;
            case 3:
                $info = "其他";
                break;
            default :
                $info = '其他';
                break;
        }
        return $info;
    }     
    //返回excel 显示宽度
    public static function Excel_width($type)
    {
        $info = "";
        switch($type)
        {
            case 'id':
                $info = 5;break;
            case 'name':
                $info = 25;break;
            case 'address':
                $info = 30;break;
            case 'bank_account':
                $info = 25;break;
            case 'bank_name':
                $info = 15;break;
            case 'bank_type':
                $info = 15;break;
            case 'tel':
                $info = 18;break;
            case 'type_id':
                $info = 20;break;
            default :
                $info = 10;break;
        }
        return $info;
    }
    //地区
    public static function Checkout_arrd($arrd)
    {
        $ar = Area::model()->findByPk($arrd);
        return $ar['name'];
    }
    
    //获取model save 时错误信息
    public static function GetErrorMassage($Model){
        
        $ErrorMessage='';
        $tmp=$Model->getErrors();
        foreach ($tmp as $k=>$v){
            $ErrorMessage .="字段:".$k."错误信息:".implode($v)."\n";
        }
        return $ErrorMessage;
        
    }
    //上传文件路径处理
    //参数 原图路径 模型 目录
    //return
    public static function UploadPathPro($oImgUrl='',$model,$dir_name){
     
        $url_root = explode($_SERVER['HTTP_HOST'],$oImgUrl);
        $oImgUrl =  $_SERVER['DOCUMENT_ROOT'] . $url_root[1];
        
    
        $save_path = dirname(__FILE__) . '/'.'/../'.'/../';;
        $save_url =  dirname($_SERVER['PHP_SELF']) . '/'.'/../'.'/../';;
        $save_path = realpath($save_path) . '/';
        
        
               //获得文件扩展名
	$temp_arr = explode(".", $oImgUrl);
	$file_ext = array_pop($temp_arr);
	$file_ext = trim($file_ext);
	$file_ext = strtolower($file_ext);
        
        
       
       
         //创建文件夹
	if ($dir_name !== '') 
        {
		$save_path .= $dir_name . "/";
		$save_url .= $dir_name . "/";
		if (!file_exists($save_path)) {
			mkdir($save_path, 0777, true);
		}
	}
        
        //以ID名为文件
        $save_path .= $model->id . "/";
	$save_url .= $model->id . "/";       
        if (!file_exists($save_path)) {
		mkdir($save_path, 0777, true);
	}
        
        //时间
	$ymd = date("Ym");
	$save_path .= $ymd . "/";
	$save_url .= $ymd . "/";
	if (!file_exists($save_path)) {
		mkdir($save_path, 0777, true);
	}
        
 
        $new_file_name = time().'.' . $file_ext;
        $file_path = $save_path . $new_file_name;
        
      //   p($oImgUrl);
     //  p_e($file_path);
//        
         return rename($oImgUrl,$file_path)?$file_path:FALSE;
        

    }
    
    
    
    
}
